package com.csw.clazzTeacher.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.csw.clazzTeacher.entity.Tag;
import com.csw.clazzTeacher.service.TagService;

@Controller
@RequestMapping("tag")
public class TagController {

	// 注入tagService
	@Autowired
	private TagService tagService;

	// 根据标签类型获取标签集合
	@RequestMapping("findByTagTypeJson")
	@ResponseBody
	public List<Tag> findByTagTypeJson(String type) {
		return tagService.findByTagType(type);
	}

	// 保存标签
	@RequestMapping("saveTag")
	public String save(Tag tag) {
		tagService.save(tag);
		return "redirect:/tag/findAllTags";
	}

	// 查询所有
	@RequestMapping("findAllTags")
	public String findAll(Model model) {
		List<Tag> tags = tagService.findAll();
		model.addAttribute("tags", tags);
		return "tag/index";
	}
}
